home *** CD-ROM | disk | FTP | other *** search
-
- -- Lua Volume Functions
- -- Copyright 2004 (c) Ron Bessems
- -- These volume make life easier for the Girder user
- -- All Constants are declared within the table LVF to avoid listing in the variable display window
- -- This file should not be modified
-
- LVF = {}
- LVF.Version = 1.09 -- version info
-
- -- DefaultMixer
- LVF.DefaultMixer = 0
-
- --Destination Type Constants
-
- LVF.DestinationTypeDestination = 0
- LVF.DestinationTypeSource = 1
-
- --Source Type Constants
- LVF.SourceTypeMaster = -1
- LVF.SourceTypeWave = 0
-
- --Control Type Constants
- -- this list includes common control tyes
-
- LVF.ControlTypeBass = 1342373890
- LVF.ControlTypeEqualizer = 1342373892
- LVF.ControlTypeFader = 1342373888
- LVF.ControlTypeMute = 536936450
- LVF.ControlTypeMux = 1879113729
- LVF.ControlTypeOnOff = 536936449
- LVF.ControlTypeTrebel = 1342373891
- LVF.ControlTypeVolume = 1342373889
- LVF.ControlTypeLoudness = 536936452
-
- -- Names -- for print purposes
- LVF.ControlTypes = {[1342373890] = "Bass", [536936450] = "Mute", [536936449] = "On/Off", [1342373891] = "Treble", [1342373889] = "Volume", [1879113729] = "Mux"}
-
-
- -- matches a control type to known listed devices above
- function GetControlTypeString(i)
- return LVF.ControlTypes [i] or i -- returns control number if unknown type
- end
-
-
- -- finds the requested control for a source
- -- returns nil if no matching control found
- function GetControlForSource (device,destination,source,controltype)
- local control
- for control=0, GetControlCount(device,destination,source)-1 do
- if GetControlType(device,destination,source,control) == controltype then
- return control
- end
- end
- end
-
-
- --Source Functions
-
- -- Set the source volume 0 - 100 %
- function SetSourceVolume (device, destination, source, volume)
- local control,type,lowerbound,upperbound,err,lvalue,rvalue,mvalue,offset,value
-
- control = GetControlForSource (device,destination,source,LVF.ControlTypeVolume)
- if not control then
- return -1
- end
-
- if volume > 100 then
- volume = 100
- end
- if volume < 0 then
- volume = 0
- end
-
- lowerbound,upperbound,type = GetControlBounds(device, destination,source,control)
- if ( type < 0 ) then
- return type
- end
-
- value = (volume / 100 * (upperbound-lowerbound)) + lowerbound
-
- -- preserve the balance
- lvalue,err = GetChannelValue (device ,destination,source,control,0,0)
- rvalue,err = GetChannelValue (device ,destination,source,control,1,0)
-
- if ( lvalue > rvalue ) then
- if ( lvalue == 0 ) then
- -- should not happen in an unsigned channel...
- else
- mvalue = lvalue
- offset = rvalue / lvalue
-
- lvalue = value
- rvalue = value * offset
- end
- else
- if ( rvalue==lvalue) then
- lvalue=value
- rvalue=value
- else
- if ( rvalue == 0 ) then
- rvalue=rvalue
- lvalue=0
- else
- mvalue = rvalue
- offset = lvalue / rvalue
- rvalue = value
- lvalue = value * offset
- end
- end
- end
-
- -- set left channel
- err = SetChannelValue(device ,destination,source,control,0,0,lvalue)
-
- if ( err <0 ) then
- return err
- end
-
- -- set right channel
- return SetChannelValue(device ,destination,source,control,1,0,rvalue)
- end
-
- -- Get the source volume in %
- function GetSourceVolume (device, destination, source)
- local err,type,lowerbound,upperbound,value
-
- lowerbound, upperbound, type = GetControlBounds (device,destination,source,GetControlForSource (device,destination,source,LVF.ControlTypeVolume) or 0)
- if ( type < 0 ) then
- return 0,type
- end
-
- value,err = GetChannelValue(device ,destination,source,GetControlForSource (device,destination,source,LVF.ControlTypeVolume) or 0,-1,0)
- if err < 0 then
- return 0,err
- else
- return round (((value-lowerbound) /(upperbound-lowerbound) * 100),0),err
- end
- end
-
- -- Set Mute for Source (1=mute, 0=unmute)
- function SetSourceMute (device, destination, source,mute)
- local control,type,lowerbound,upperbound,value
-
- control = GetControlForSource (device,destination,source,LVF.ControlTypeMute)
- if not control then
- return -1
- end
-
- if mute > 1 then
- mute = 1
- end
- if mute < 0 then
- mute = 0
- end
-
- lowerbound,upperbound, type = GetControlBounds (device, destination,source,control)
-
- if ( type < 0 ) then
- return type
- end
-
- value = (mute * (upperbound-lowerbound)) + lowerbound
-
- return SetChannelValue (device ,destination,source,control,-1,0,value)
- end
-
- -- Get control Mute
- function GetSourceMute (device,destination,source)
- return GetChannelValue (device ,destination,source,GetControlForSource (device,destination,source,LVF.ControlTypeMute) or 1,-1,0)
- end
-
-
- -- Control Level Functions
-
- function SetControlBalance (device, destination, source, control, balance)
- -- - 100 = left
- -- + 100 = right
- -- 0 = center
- local balance,err,mvalue,lvalue,rvalue
-
- if balance > 100 then
- balance = 100
- end
-
- if balance < -100 then
- balance = -100
- end
-
- -- first get the max value
- mvalue,err = GetChannelValue (device, destination, source, control, -1,0)
- if (err<0) then
- return err
- end
-
- -- now determine left and right value
- if ( balance < 0 ) then
- balance = balance + 100
- lvalue = mvalue
- rvalue = mvalue * balance / 100
- else
- balance = 100 - balance
- lvalue = mvalue * balance / 100
- rvalue = mvalue
- end
-
- err = SetChannelValue (device ,destination,source,control,0,0,lvalue)
- if ( err <0 ) then
- return err
- end
- return SetChannelValue (device ,destination,source,control,1,0,rvalue)
- end
-
-
-
- -- Quick and Easy Functions
-
- -- 1. Master on Default Mixer
-
- -- Set the master volume 0 - 100 %
- function SetMasterVolume (volume)
- return SetSourceVolume (LVF.DefaultMixer,LVF.DestinationTypeDestination,LVF.SourceTypeMaster,volume)
- end
-
- -- Get Master Volume %
- function GetMasterVolume ()
- return GetSourceVolume (LVF.DefaultMixer,LVF.DestinationTypeDestination,LVF.SourceTypeMaster)
- end
-
- -- Mutes the master channel (1=mute, 0=unmute)
- function SetMasterMute (mute)
- return SetSourceMute (LVF.DefaultMixer,LVF.DestinationTypeDestination,LVF.SourceTypeMaster,mute)
- end
-
- -- Get Master Mute
- function GetMasterMute ()
- return GetSourceMute (LVF.DefaultMixer,LVF.DestinationTypeDestination,LVF.SourceTypeMaster)
- end
-
-
- -- 2. Wave on Default Mixer
-
- -- Set the wave volume 0 - 100 %
- function SetWaveVolume (volume)
- return SetSourceVolume (LVF.DefaultMixer,LVF.DestinationTypeDestination,LVF.SourceTypeWave,volume)
- end
-
- -- Get Wave Volume %
- function GetWaveVolume ()
- return GetSourceVolume (LVF.DefaultMixer,LVF.DestinationTypeDestination,LVF.SourceTypeWave)
- end
-
- -- Mutes the wave channel (1=mute, 0=unmute)
- function SetWaveMute (mute)
- return SetSourceMute (LVF.DefaultMixer,LVF.DestinationTypeDestination,LVF.SourceTypeWave,mute)
- end
-
- -- Get Wave Mute
- function GetWaveMute ()
- return GetSourceMute (LVF.DefaultMixer,LVF.DestinationTypeDestination,LVF.SourceTypeWave)
- end
-
-
- -- Display Entire Mixer
-
- function MixerPrintDetails (device)
- local DestCnt,i,SrcCnt,err,name,CtrlCnt,k,type,s,j,ItemCnt,l,value
-
- device = device or LVF.DefaultMixer
-
- name,err = GetDeviceName (device)
-
- if err < 0 then
- print ("Error opening sound card: ",device)
- return
- end
-
- print ("Enumerating Sound Card Controls for device number ",device,".")
- print ("")
- print (name)
-
- DestCnt = GetDestinationCount(device)
- if ( DestCnt <0 ) then
- print ("Error opening sound card:"..device)
- return
- end
-
- for i=0,DestCnt-1 do
-
- name,err = GetDestinationName (device, i)
- print (" ",name)
-
- -- request sourcecount of the current destination (i)
- SrcCnt = GetSourceCount (device, i)
-
- -- start at -1 to include the master channel as well
- for j=-1, SrcCnt-1 do
-
- -- now we are accessing the name of the source, this needs
- -- two indices i and j.
- name,err = GetSourceName (device, i,j)
- print (" "..name) -- indented for clarity
-
- -- get the number of controls on the current source
- CtrlCnt = GetControlCount (device, i,j)
-
- for k=0, CtrlCnt-1 do
-
- name,err = GetControlName (device,i,j,k)
- type = GetControlType (device,i,j,k)
- s = GetControlTypeString (type)
- value,err = GetChannelValue (device,i,j,k, -1,0)
- print (" "..name.." (" .. s.." control) value: ",value)
- ItemCnt = GetItemCount (device,i,j,k)
-
- for l=0, ItemCnt-1 do
- name,err = GetItemName (device,i,j,k,l)
- value,err = GetChannelValue (device,i,j,k,0,l)
- print (" *"..name..", Value: " ..value)
- end
- end
- end
- end
- CloseVolumeControls(device)
- end
-
- print ("LUA Volume Functions Loaded, Version: ",LVF.Version)
-
-
-
-
-